﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.views.world.machines {
    import flash.events.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.world.vos.*;
    import __AS3__.vec.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.models.world.vos.actors.machines.*;
    import mx.utils.*;
    import net.wooga.pets.constants.*;

    public class SlotMachineMediator extends AbstractMachineMediator {

        public var sessionModel:SessionModel;
        private var _addedItems:Vector.<RewardItemVO>;
        private var _allRewardItems:Array;

        private function get view():SlotMachineView{
            return ((viewComponent as SlotMachineView));
        }
        private function get vo():SlotMachineVO{
            return ((_vo as SlotMachineVO));
        }
        override protected function updateActor(_arg1:Object):void{
            this.view.handleAnimation(this.vo.state);
        }
        override public function onRegister():void{
            super.onRegister();
            this._allRewardItems = [];
            eventMap.mapListener(eventDispatcher, EventConstants.SLOTMACHINE_ITEMS_RECEIVED, this.onItemsReceived);
            eventMap.mapListener(eventDispatcher, EventConstants.COLLECT_REWARD_ITEM, this.onTakeRewardItem);
            eventMap.mapListener(this.view, EventConstants.SLOTMACHINE_ANIMATION_FINISHED, this.onSlotmachineAnimationFinished);
            this.view.setCoinAnimationText(("- " + languageModel.getTextByKey("global_amount_coins", {amount:GameConstants.SLOTMACHINE_COSTS})));
        }
        private function onItemsReceived(_arg1:InfoEvent):void{
            this._addedItems = (_arg1.info.addedItems as Vector.<RewardItemVO>);
            this._allRewardItems = (((_arg1.info.allItems as Array)) || ([]));
            var _local2:Array = this.vo.getSlotNamesList(this._addedItems);
            this.view.renderResult(_local2);
        }
        private function onSlotmachineAnimationFinished(_arg1:Event):void{
            dispatch(new InfoEvent(EventConstants.CREATE_REWARD_ICONS, this.vo.roomId, this._allRewardItems));
            this._allRewardItems = [];
        }
        private function onTakeRewardItem(_arg1:InfoEvent):void{
            l(("onTakeRewardItem: " + _arg1.id));
            var _local2:int;
            while (_local2 < this._allRewardItems.length) {
                if (_arg1.id == this._allRewardItems[_local2].id){
                    l(("remove " + ObjectUtil.toString(this._allRewardItems[_local2])));
                    this._allRewardItems.splice(_local2, 1);
                    break;
                };
                _local2++;
            };
        }

    }
}//package net.wooga.pets.views.world.machines 
